package com.happyclub.paul.dao;

import com.happyclub.pojo.TbPhotoAlbum;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @Auther: 魏泉琦
 * @Date: 2019/4/3 15:36
 * @Description: 相册表
 */
public interface PhotoAlbumRepostitory extends JpaRepository<TbPhotoAlbum,String> {

    /**
     *@Description: 将用户创建相册 保存到相册表中
     *@Author: 魏泉琦
     *@date: 2019/4/3
     */
    @Modifying
    @Query(value = "insert into TB_PHOTO_ALBUM(ID,CREATE_TIME,ALBUM_NAME) values(?1,SYSDATE,?2)",nativeQuery = true)
    Integer saveUserPhotoAlbumMsg(String id, String photoAlbumName);


    /**
     *@Description: 通过中间表的相册编号查询主表中的相册信息
     *@Author: 魏泉琦
     *@date: 2019/4/6
     */
    @Query(value = "SELECT ID,ALBUM_NAME,ALBUM_DEFAULT_PICTURE,CREATE_TIME,UPDATE_TIME from TB_PHOTO_ALBUM WHERE ID= ?1",nativeQuery = true)
    TbPhotoAlbum queryPhotoAlbumsById(String photoAlbumId);


    /**
     *@Description: 通过相册编号删除对应相册
     *@Author: 魏泉琦
     *@date: 2019/4/6
     */
    @Modifying
    @Query(value = "DELETE from TB_PHOTO_ALBUM where ID=?1",nativeQuery = true)
    Integer deletePhotoAlbumById(String albumId);



    /**
     *@Description: 查询要修改的相册信息，回显
     *@Author: 魏泉琦
     *@date: 2019/4/9
     */
    @Query(value = "SELECT ID,ALBUM_NAME,ALBUM_DEFAULT_PICTURE,CREATE_TIME,UPDATE_TIME  from TB_PHOTO_ALBUM where ID=?1",nativeQuery = true)
    TbPhotoAlbum queryEditAlbumNameByAlbumId(String albumId);


    /**
     *@Description: 保存修改的相册信息
     *@Author: 魏泉琦
     *@date: 2019/4/9
     */
    @Modifying
    @Query(value = "UPDATE TB_PHOTO_ALBUM SET ALBUM_NAME=:albumName,UPDATE_TIME=SYSDATE WHERE ID=:albumId",nativeQuery = true)
    Integer saveEditAlbumName(@Param("albumId") String albumId,@Param("albumName") String albumName);

}
